import React from 'react'
import { useSelector, useDispatch } from 'react-redux'
import { Todoclear } from '../../store/actions/todo'

export default function TodoFooter () {
  const dispatch = useDispatch()
  const list = useSelector((state) => state.todo)
  const doenLength = list.filter((item) => item.done === false).length
  // 清空已完成
  const handleClick = () =>{
    dispatch(Todoclear())
  }
  return (
    <footer className='footer'>
      <span className='todo-count'>
        <strong>{doenLength}</strong> item left
      </span>
      <ul className='filters'>
        <li>
          <a className='selected' href='#/'>
            All
          </a>
        </li>
        <li>
          <a href='#/active'>Active</a>
        </li>
        <li>
          <a href='#/completed'>Completed</a>
        </li>
      </ul>
      <button className='clear-completed' onClick={handleClick}>Clear completed</button>
    </footer>
  )
}